how to solve factorial equation